/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package manage_image;

import Manager_Image_Utils.Constants;
import Manager_Image_Utils.Library;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.security.CodeSource;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultListModel;
import javax.swing.JLabel;

/**
 *
 * @author Admin
 */
public class Abum extends JLabel{
    private int numimages;
    String Name;
    File fdir;
    Constants c=new Constants();

    public int getNumimages() {
        return numimages;
    }

    public void setNumimages(int numimages) {
        this.numimages = numimages;
    }

    public String getName() {
        return Name;
    }

    public void setName(String Name) {
        this.Name = Name;
    }

    public File getFdir() {
        return fdir;
    }

    public void setFdir(File fdir) {
        this.fdir = fdir;
    }
    
    public Abum(int numimages, String Name, File fdir) {
        this.numimages = numimages;
        this.Name = Name;
        this.fdir = fdir;
        setText(Name +String.valueOf(numimages));
        setIcon(c.icabum);
    }

    @Override
    public String toString() {
        return getName()+" ( "+String.valueOf(getNumimages())+" ) ";
    }
    
    public static File GetAbumDir(){
        CodeSource codeSource =Manage_Image.class.getProtectionDomain().getCodeSource();
        File jarFile=null; 
        try {
            jarFile= new File(codeSource.getLocation().toURI().getPath());
        } catch (URISyntaxException ex) {
            Logger.getLogger(Abum.class.getName()).log(Level.SEVERE, null, ex);
        }
        return new File(jarFile.getPath()+"\\Abums\\");
    }
    
    public static ArrayList<Abum> GetList(){
        File fs=GetAbumDir();
        if (!fs.exists())
        {
            fs.mkdir();
        }
        ArrayList<Abum> result=new ArrayList<Abum>();
        int coutf=fs.listFiles().length;
        for(File f:fs.listFiles()){
            int count=0;
            for(File ab:f.listFiles()){
                if(Library.isImage(ab.getPath())){
                    count++;
                }
            }
            Abum abum=new Abum(count, f.getName(), f);
            result.add(abum);
        }
        return result;
    }
    public static boolean Create(String AbumName){
        File theDir = new File(GetAbumDir().getPath()+"/"+AbumName);
        if (!theDir.exists())
        {
            boolean result = theDir.mkdir();  
            if(result){    
               return true; 
            }
            return false;
        }
        return false;
    }
}
